package com.mmy.dao.restaurant;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.mmy.domain.restaurant.TRestaurantBase;

public interface TRestaurantBaseRepository extends JpaRepository<TRestaurantBase, Integer> {

	/**
	 * 获取最大值ID
	 * 
	 * @return 返回值说明 最大ID
	 * @author 创建人 dingxd
	 * @date 创建日期 2020.11.17
	 */
	@Query(value = "SELECT MAX(iRestaurantID) FROM tRestaurantBase WHERE LEFT(iRestaurantID,2) = RIGHT(YEAR(NOW()),2)", nativeQuery = true)
	Object getMaxRestaurantID();

	/* 创建餐馆信息 */
	@Transactional
	@Modifying
	@Query(value = "INSERT INTO tRestaurantBase(iRestaurantID, cRestaurantName, cContact, cTel, cRate, iScenicID, iZoneID, cAddress, cIntro, iNumber, iRoom, cImgPath, dCreateDate, cCreator, dModifyDate, cReviser, cMemo, cSpare1, cSpare2, cSpare3, cSpare4, cSpare5) VALUES (?1, NULL, NULL, NULL, NULL, 0, 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)", nativeQuery = true)
	void save(int iRestaurantID);

	/* 根据id查找 */
	@Query(value = "select *  from tRestaurantBase where iRestaurantID = ?1", nativeQuery = true)
	TRestaurantBase findByRestaurantID(int iRestaurantID);;

	/* 删除餐馆信息 */
	@Transactional
	@Modifying
	@Query(value = "delete from tRestaurantBase where iRestaurantID in (:iRestaurantIDs)", nativeQuery = true)
	void deleteChecked(@Param("iRestaurantIDs") List<Integer> iRestaurantIDs);

	/**
	 * 前台景区电子票菜单显示景区信息 分页
	 * 
	 * @return 返回值说明
	 * @author 创建人hanxl
	 * @param iPageSize
	 * @param iTempPageNo
	 * @date 创建日期 2020.12.24
	 */
	@Query(value = "select count(*)  from tRestaurantBase where iRestaurantID in(:lstRestID)", nativeQuery = true)
	int countSearch(@Param("lstRestID") List<Integer> lstRestID);

}
